package com.innoking.docsys.user.controller;

import com.innoking.docsys.user.dto.UpmsUser;
import com.innoking.docsys.user.module.UpmsRoleVO;
import com.innoking.docsys.user.module.UpmsUserRoleObjVO;
import com.innoking.docsys.user.module.UpmsUserVO;
import com.innoking.docsys.user.service.UserRoleRelationService;
import com.innoking.docsys.user.service.UserService;
import com.innoking.docsys.utils.JsonToOtherUtil;
import com.innoking.docsys.utils.OtherPojo;
import com.innoking.docsys.utils.ResultObjVO;
import com.innoking.docsys.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Administrator on 2019/8/15.
 */
@RestController
@RequestMapping("/api/userRole")
public class UserRoleController {
    Logger logger= LoggerFactory.getLogger(UserRoleController.class);

    @Autowired
    UserService userService;

    @Autowired
    UserRoleRelationService userRoleRelationService;


//    @PostMapping("/getUserRole")
//    public ResultObjVO getUserRole(@RequestBody String data) {
//
//        logger.info("Hello getUserRole");
//        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data, new UpmsUserVO() );
//        UpmsUserVO user=(UpmsUserVO)ob.getObj();
//        UpmsUser userRes=userService.getUserbyId( user.getUserId().intValue() );
//        UpmsUserVO vo= new UpmsUserVO();
//        BeanUtils.copyProperties(userRes,vo);
//        return  ResultUtil.success(vo);
//
//    }

    /**
     * 获取用户权限对象及角色列表
     * @param data
     * @return
     */
    @PostMapping("/getUserRoleList")
    public ResultObjVO getUserRoleList(@RequestBody String data) {

        logger.info("Hello getUserRoleList");
        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data, new UpmsUserVO() );
        UpmsUserVO user=(UpmsUserVO)ob.getObj();

        UpmsUserRoleObjVO objVO=userRoleRelationService.getUserRoleList( user.getUserId().intValue() );

        return  ResultUtil.success(objVO);

    }

}